package servlet.comm;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import factory.comm.HomeworkDAOFactory;
import vo.comm.Homework;

public class ScoreHomeworkServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public ScoreHomeworkServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	String userida=(String) request.getSession().getAttribute("userida");
	String useridc=(String) request.getSession().getAttribute("userid");
	String homeworkid=(String) request.getSession().getAttribute("homeworkid");
	String score=request.getParameter("score");
	Homework homework=new Homework();
	homework.setUserida(userida);
	homework.setUserid(useridc);
	homework.setHomeworkid(homeworkid);
	homework.setScore(score);
	try {
		if(HomeworkDAOFactory.getIHomeworkDAOInstance().doScore(homework)){
			response.sendRedirect("homework/score_success.jsp");
		}
		else{
			response.sendRedirect("homework/score_failure.jsp");
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	}

}
